<!--
 * @Descripttion: 
 * @version: 
 * @Author: ck
 * @Date: 2021-05-08 11:05:46
 * @LastEditors: ck
 * @LastEditTime: 2021-06-30 17:43:09
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="file" accept="image/*" name="fileName" id="upImg">
    <script>
        let upImg = document.querySelector("#upImg");
        upImg.addEventListener('change', function () {
            let file = this.files[0];
            // 将blob对象转为url
            // const url = URL.createObjectURL(file);
            // console.log(url);
            let fileReader = new FileReader();
            fileReader.readAsDataURL(file);
            fileReader.addEventListener('load', function (e) {
                let img = new Image();
                img.addEventListener('load', function () {
                    if (this.width != 413 || this.height != 626) {
                        alert("请上传标准2寸照片")
                        return
                    }
                    //两寸宽高413×626
                    document.body.appendChild(this)
                })
                //base64数据
                img.src = this.result;
            })
        })
    </script>
</body>

</html>